package com.ranjiaqi.homework;

import java.io.*;

/**
 * @ClassName HomeWork
 * @Description TODO
 * @Author hp
 * @Date 2021/7/1 14:11
 * @Version 1.0
 **/
public class HomeWork {
    public static void main(String[] args) throws IOException {
//        homeWork01();
//        homeWork02();
//        homeWork03();


        FileReader fileReader = new FileReader("F:/java/h3.txt");
        int temp;
        while ((temp = fileReader.read())!=-1){
            System.out.println();
        }
        fileReader.close();
    }

    public static void homeWork01() {
        try (BufferedWriter bfw = new BufferedWriter(new FileWriter("F:/java/h1.txt"));
             BufferedReader bfr = new BufferedReader(new FileReader("F:/java/h1.txt"))) {
            String str = null;
            bfw.write("奔赴星空");
            bfw.flush();
            while ((str = bfr.readLine()) != null) {
                System.out.println(str);
            }

        } catch (IOException E) {
            E.printStackTrace();
        }
    }

    public static void homeWork02() {
        try (BufferedWriter bfw = new BufferedWriter(new FileWriter("F:/java/h2.txt"))
             ; BufferedReader bfr = new BufferedReader(new FileReader("F:/java/h2.txt"))) {
            bfw.write("姓名:冉佳奇");
            bfw.newLine();
            bfw.flush();
            bfw.write("性别:男");
            bfw.newLine();
            bfw.flush();
            bfw.write("年龄:23");
            bfw.newLine();
            bfw.flush();
            bfw.write("班级:JAVA0601");
            bfw.newLine();
            bfw.flush();
            String line = null;
            while ((line = bfr.readLine()) != null) {
                System.out.println(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        new File("F:/java/h2.txt").delete();
    }

    public static void homeWork03() {
        try (BufferedWriter bfw = new BufferedWriter(new FileWriter("F:/java/h3.txt"));
             BufferedReader bfr = new BufferedReader(new FileReader("F:/java/h3.txt"));
             BufferedWriter bfw2 = new BufferedWriter(new FileWriter("F:/java/h4.txt"))) {
            bfw.write("你");
            bfw.newLine();
            bfw.flush();
            bfw.write("你们");
            bfw.newLine();
            bfw.flush();
            bfw.write("大家");
            bfw.newLine();
            bfw.flush();

            String line = null;
            while ((line = bfr.readLine()) != null) {
                bfw2.write(line + "好");
                bfw2.newLine();
            }
            bfw2.write("完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
